<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/operateTag" prefix="o"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>权限管理</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
	<jsp:include page="/page/head.jsp"></jsp:include>
	<script type="text/javascript">
		var path = "<%=path%>";
		
		var url = path + "permission/list.do";
		
		$(document).ready(function(){
		    $('#mgrTable').treegrid();  
		});
		
		function add(){
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				window.location = path+"/permission/init.do?type=add&permissionId="+selected.id;
			}else{
				alertBox("请选择父权限节点！");
			}
		}
		
		function edit(){
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				window.location = path+"/permission/init.do?type=edit&permissionId="+selected.id;
			}else{
				alertBox("请选择需要编辑的权限！");
			}
		}
		
		function remove(){
			var selected = $('#mgrTable').treegrid('getSelected');
			if(selected){
				var submit = function (v, h, f) {
				    if (v == 'ok'){
				    	var _url = path +"/permission/delete.do?permissionId="+selected.id+"&t="+new Date().getTime();
						$.ajax({
						  url: _url,
						  success: function(data) {
							   if(data == "1")
							   {
									$('#mgrTable').treegrid('reload');
									alertBox("操作成功！");
								} else {
									alertBox("操作失败！");
								}
						  }
						});
				    }
				    	
				    return true; //close
				};
				
				$.jBox.confirm("确定要删除吗？", "提示", submit);
				
			}else{
				alertBox("请选择需要删除的权限！");
			}
		}
		
		function refresh(){
			$('#mgrTable').treegrid('reload');
		}
		
		function typeFormatter(value,rec){
          	if(value == "0"){
				return "菜单权限";
			}
			return "操作权限";
        }
		
		function showFormatter(value,rec){
          	if(value == "0"){
				return "是";
			}
			return "否";
        }
		
	</script>

  </head>
  
  <body>
    <div class="right">
		<h1><b>权限管理</b><span><img src="<%=basePath %>images/right_h1bg2.jpg" width="3" height="29" /></span></h1>
		<div class="ri_main">
			<div id="toolbar">
				<a href="javascript:void(0);" onclick="add()" class="easyui-linkbutton" iconCls="icon-add">新增</a>
				<a href="javascript:void(0);" onclick="edit()" class="easyui-linkbutton" iconCls="icon-edit">编辑</a>
				<a href="javascript:void(0);" onclick="remove()" class="easyui-linkbutton" iconCls="icon-remove">删除</a>
				<a href="javascript:void(0);" onclick="refresh()" class="easyui-linkbutton" iconCls="icon-reload">刷新</a>
			</div>
		 	<table id="mgrTable" toolbar="#toolbar" idField="id" treeField="name" url="permission/list.do"
		 		singleSelect="true" rownumbers="true" animate="true">
		 		<thead>
					<tr>
						<th field="name" width="200" frozen="true">权限名称</th>
						<th field="type" width="100" formatter="typeFormatter">权限类型</th>
						<th field="isDelete" width="80" formatter="showFormatter">是否显示</th>
						<th field="id" width="80">权限编号</th>
						<th field="layerOrder" width="200">排序编号</th>
					</tr>
				</thead>
		 	</table>  
		</div>
	</div>
  </body>
</html>
